package com.factory.factorymethod.self.order;

import com.factory.factorymethod.self.pizza.Cake;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public abstract class OrderPizza {
    public OrderPizza() {
        Cake cake;
        String type;
        do {
            type = getType();
            cake = createCake(type);
            if(cake!=null){
               cake.prepare();
               cake.ferment();
               cake.cut();
               cake.box();
            }else {
                System.out.println("没有这种类型的蛋糕或者蛋糕创建失败");
            }
        } while (true);
    }

    public abstract Cake createCake(String type);

    public String getType(){
        try {
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("请输入要制作蛋糕的类型:");
            String readLine = bufferedReader.readLine();
            return readLine;
        } catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }
}
